package cn.netjava.robo3d.test;

import com.jme.math.FastMath;

import cn.netjava.robo3d.RoboTank;
import cn.netjava.robo3d.event.HitByBulletEvent;
import cn.netjava.robo3d.event.HitByFireEvent;
import cn.netjava.robo3d.event.HitWallEvent;
import cn.netjava.robo3d.event.ImpactCarEvent;
public class Robot1 extends RoboTank {


	private long count=0;
    private int dir=-1;
	//实现人工智能的地方
	public Robot1(){
		//每个机器人都要调用父类的构造器,以初始化数据
		super("robot1");

	}
	public void onhitbybullet(HitByBulletEvent evt) {
		this.jump();
		for(int i=0;i<45;i++){
				this.controloilrate();
			  }
	}
    public void onhitbyfire(HitByFireEvent evt){
		this.setdirection(dir);
		dir=(-dir);
		for(int i=0;i<25;i++){
			this.controloilrate();
		  }
		this.firegun();
		
	}
	public void onhitwall(HitWallEvent evt) {
		
	}
	//当撞到其它坦克时
    public void onimpactcar(ImpactCarEvent evt){
		this.setdirection(dir);
		dir=(-dir);
      for(int i=0;i<10;i++){
    	controloilrate();
    	this.firegun();
    	this.turnright();
      }
      this.jump();
      this.endfiregun();
      for(int j=0;j<30;j++){
    	  this.leftcasemate(8f);
    	  this.firegun();
      }
      
      for(int k=0;k<10;k++){
    	  this.rightcasemate(5f);
    	  this.controloilrate();
    	  this.pause(2);
      }
      
    }
	public void run(){
		System.out.println(this.getName()+"  :机器人启动");

		while(true){
		  for(int i=0;i<30;i++){
			this.controloilrate();
			this.pause(14);
		  }

		  for(int j=0;j<20;j++){
		  this.turnleft();
		  }
		  this.leftcasemate(50f);
		  
		  this.pause(3);
		  this.endfiregun();
//			System.out.println("robot1-speed:"+this.getspeed());
				float rand=(float)Math.random()*4;
			
				rand=(int)Math.ceil(rand);
				if(rand==2)this.shoot();
				this.endfiregun();
			
		}

	}

}
